package com.xunk.equipment.api.factory;

import com.xunk.common.core.domain.ControlDeviceParam;
import com.xunk.common.core.web.domain.AjaxResult;
import com.xunk.equipment.api.RemoteEquipmentService;
import com.xunk.equipment.api.domain.MessageNotificationDO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.equipment.api.factory
 * @ClassName: remoteEquipmentFallbackFactory
 * @Author: dongxiaoxin
 * @Description: 降级实现类
 * @Date: 2021/4/6 15:10
 * @Version: 1.0
 */
@Component
public class RemoteEquipmentFallbackFactory implements FallbackFactory<RemoteEquipmentService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteEquipmentFallbackFactory.class);

    @Override
    public RemoteEquipmentService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteEquipmentService() {
            @Override
            public AjaxResult controlDevice(List<ControlDeviceParam> list) {
                return AjaxResult.error("调整设备属性失败");
            }

            @Override
            public AjaxResult controlDevice(@RequestHeader(name = "secret") String secret, List<ControlDeviceParam> list) {
                return AjaxResult.error("调整设备属性失败");
            }

            @Override
            public AjaxResult deleteRuyingDevice(String deviceSns, Long deptId) {
                return AjaxResult.error();
            }

            @Override
            public AjaxResult insertMessageNotification(List<MessageNotificationDO> messages) {
                return AjaxResult.error();
            }

            /**
             * 根据设备号查询设备信息
             *
             * @param deviceSn
             * @return
             */
            @Override
            public AjaxResult info(String deviceSn) {
                return AjaxResult.error();
            }

            /**
             * 获取某个家庭下的所有设备列表
             *
             * @param homeId
             * @param deviceSource
             * @return
             */
            @Override
            public AjaxResult list(Long homeId, Integer deviceSource) {
                return AjaxResult.error();
            }
        };
    }
}
